package cate.game.play.vo;

import cate.game.play.fighter.Fighter;
import cate.game.play.part.FightTeam;

import java.util.ArrayList;
import java.util.List;

public class TeamStatVO {

	public List<FighterStatVO> fighters = new ArrayList<>();

	public TeamStatVO read(FightTeam fightTeam) {
		for (Fighter fighter : fightTeam.getAllHero()) {
			fighters.add(new FighterStatVO().read(fighter));
		}
		return this;
	}

	public void merge(TeamStatVO stat){
		for (FighterStatVO fighter : stat.fighters) {
			FighterStatVO old = getOrBuildFighter(fighter.pid);
			old.merge(fighter);
		}
	}

	private FighterStatVO getOrBuildFighter(int pid) {
		for (FighterStatVO fighter : fighters) {
			if (fighter.pid == pid) {
				return fighter;
			}
		}
		FighterStatVO stat = new FighterStatVO();
		stat.pid = pid;
		fighters.add(stat);
		return stat;
	}

	public void divide(int num) {
		for (FighterStatVO fighter : fighters) {
			fighter.divide(num);
		}
	}
}
